﻿using System;
using System.Collections.Generic;

class DurankulakNumbers
{
    static void Main()
    {
        string[] durankulagDigits = GetDurankulakDigits();

        string durankulakNumber = Console.ReadLine();

        List<uint> decimalRepresentations = GetDecimalRepresantations(durankulagDigits, durankulakNumber);

        //foreach (var item in decimalRepresentations)
        //{
        //    Console.WriteLine(item);
        //}
        ulong decimalNumber = GetDecimalNumber(decimalRepresentations);
        Console.WriteLine(decimalNumber);
    }

    static ulong GetDecimalNumber(List<uint> decimalRepresentations)
    {
        ulong result = 0;
        for (int i = 0; i < decimalRepresentations.Count; i++)
        {
            result += decimalRepresentations[decimalRepresentations.Count - i - 1] * (ulong)Math.Pow(168, i);
        }
        return result;
    }

    static List<uint> GetDecimalRepresantations(string[] durankulagDigits, string durankulakNumber)
    {
        List<uint> decimalRepresentations = new List<uint>();
        char buffer = new char();   // '\u0000'

        foreach (char symbol in durankulakNumber)
        {
            if (symbol >= 'A' && symbol <= 'Z')
	        {
                string durankulakDigit = null;
                uint decimalRepresantation = 0;
                if (buffer != default(char))
                {
                    durankulakDigit = string.Format("{0}{1}", buffer, symbol);    
                    buffer = default(char);
                }
                else
                {
                    durankulakDigit = symbol.ToString();
                }
                decimalRepresantation = (uint)Array.IndexOf(durankulagDigits, durankulakDigit);
                decimalRepresentations.Add(decimalRepresantation);
		 
	        }
            else
	        {
                buffer = symbol;
	        }
        }
        return decimalRepresentations;
    }

    static string[] GetDurankulakDigits()
    {
        string[] durankulagDigits = new string[168];
        
        for (int i = 0; i < 168; i++)
		{            
			if (i < 26)
	        {
                durankulagDigits[i] = ((char)('A' + i)).ToString();
                         //TODO: append durankulak digits
	        }
            else if (i < 2 * 26)
	        {
                durankulagDigits[i] = "a" + durankulagDigits[i - 26];
                //durankulagDigits[i] = string.Format("{0}{1}", "a", durankulagDigits[i - 26]);
		 
	        }
            else if (i < 3 * 26)
	        {
                durankulagDigits[i] = "b" + durankulagDigits[i - 2 * 26];
		 
	        }
            else if (i < 4 * 26)
	        {
                durankulagDigits[i] = "c" + durankulagDigits[i - 3 * 26];
		 
	        }
            else if (i < 5 * 26)
	        {
                durankulagDigits[i] = "d" + durankulagDigits[i - 4 * 26];
		 
	        }
            else if (i < 6 * 26)
	        {
                durankulagDigits[i] = "e" + durankulagDigits[i - 5 * 26];
		 
	        }
            else
	        {
                durankulagDigits[i] = "f" + durankulagDigits[i - 6* 26];

	        }
		}

        return durankulagDigits;
    }
}

